<?php
namespace Modules\Order\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
use Modules\Good\Http\Resources\GoodResource;
class OrderDetailResource extends JsonResource{
    public function toArray($request): array{
        return [
            'id'=>$this->id,
            'user_id'=>$this->user_id,
            'goods_id'=>$this->goods_id,
            'price'=>$this->price,
            'num'=>$this->num,
            'goods'=>$this->includeGoods(),
        ];
    }
    public function includeGoods(){
        return $this->whenLoaded('goods',function($goods){
            return new GoodResource($goods);
        });
    }

}
